package org.wisdom.data.jpa.support;

import cn.hutool.extra.spring.SpringUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Assert;

import javax.persistence.PrePersist;

/**
 * 编码监听
 *
 * @author zhangzhiyan
 * @date 2022/05/06 15:56
 **/
@Configuration
public class WisdomEntityListener {

    @PrePersist
    public void touchForCreate(Object target) {
        Assert.notNull(target, "Entity must not be null!");
        WisdomEntityHandler wisdomEntityHandler = SpringUtil.getBean(WisdomEntityHandler.class);
        if (wisdomEntityHandler != null) {
            wisdomEntityHandler.markCreated(target);
        }
    }
}
